package cn.mi.mishop.user.service.impl;

import cn.mi.mishop.user.mapper.UserMapper;
import cn.mi.mishop.user.pojo.dto.UserDto;
import cn.mi.mishop.user.pojo.dto.UserLoginDto;
import cn.mi.mishop.user.pojo.entity.User;
import cn.mi.mishop.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Slf4j
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;

    @Override
    public void addUser(UserDto userDto) {
        User user = new User();
        BeanUtils.copyProperties(userDto, user);
        user.setCreateTime(new Date());
        userMapper.addUser(user);
    }

    @Override
    public void login(UserLoginDto userLogin){
        UserLoginDto userLoginDto = new UserLoginDto();
        BeanUtils.copyProperties(userLogin, userLoginDto);
        User user = userMapper.login(userLoginDto);
        if (user == null){
            log.info("用户不存在");
             return;
        }else{
            log.info("用户登录失败,用户名或密码错误");
        }

    }
}
